<template>
  <div class="profile-create">
    <div class="content">
      <div class="box-item" v-for="(item,index) in finalCreateList"
           :key="index" @click="itemClick(index)">
        <div class="left">
          <img :src="item.listPic" alt="">
        </div>
        <div class="title">
          <p>{{item.listName}}</p>
        </div>
        <div class="count">
          <p>{{item.listCount}}首</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {getCreateList} from "../../../network/userabout";

  export default {
        name: "ProfileCreateList",
        data(){
          return{
              finalCreateList:[],
              finalCollectList:[],
              createListInfo:{},
              createCollectInfo:{},
          }
        },
        mounted() {
            if(Object.keys(this.$store.state.userInfo).length != 0){
                let userinfo = this.$store.state.userInfo
                if(userinfo.constructor === String){
                    userinfo = JSON.parse(userinfo)
                }
                getCreateList(userinfo.userid).then(res=>{
                    var detail = res.data.playlist
                    var username = userinfo.username
                    for(let i =1; i<detail.length; i++){
                        if(detail[i].creator.nickname == username){
                            this.createListInfo={
                                listId:detail[i].id,
                                listName:detail[i].name,
                                listPic:detail[i].coverImgUrl,
                                listCount:detail[i].trackCount,
                            }
                            this.finalCreateList.push(this.createListInfo)
                        }else if(detail[i].creator.nickname !== username){
                            this.createListInfo={
                                listId:detail[i].id,
                                listName:detail[i].name,
                                listPic:detail[i].coverImgUrl,
                                listCount:detail[i].trackCount,
                            }
                            this.finalCollectList.push(this.createListInfo)
                        }
                    }
                    this.$store.commit('getCreateListInfo',this.finalCreateList)
                    this.$store.commit('getCollectListInfo',this.finalCollectList)

                })
            }
        },
      methods:{
          itemClick(index){
              // console.log(this.finalCreateList[index].listId)
              this.$router.push('/songlist/' + this.finalCreateList[index].listId)
          }
      }
  }
</script>

<style scoped>
  .profile-create{
    margin-top: 10px;
  }

  .content{
    width: 100%;
    margin-bottom: 15px;
  }

  .box-item{
    height: 80px;
    margin-bottom: 10px;
    position: relative;

  }

  .left{
    width: 45px;
    height: 45px;
  }

  .left img{
    width: 80px;
    height: 80px;
    border-radius: 5px;
  }

  .title{
    height: 22px;
  }

  .title p{
    vertical-align: center;
    position: absolute;
    top: 8px;
    left: 95px;
    font-size: 16px;
    font-weight: 500;
  }

  .count{
    height: 23px;
  }


  .count p{
    vertical-align: center;
    font-size: 12px;
    position: absolute;
    left: 95px;
    top: 35px;
  }


</style>